home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_rpm.idb / usr / freeware / lib / rpm / convertrpmrc.sh.z / convertrpmrc.sh
Linux/UNIX/POSIX Shell Script  |  2000-01-25  |  2KB  |  105 lines

  1. #!/bin/sh
  2. #
  3. # Convert per-system configuration in /etc/rpmrc to macros in /etc/rpm/macros.
  4. #
  5. # prereq: awk fileutils textutils sh-utils mktemp
  6. #
  7.  
  8. RPMRC=/etc/rpmrc
  9. MACROS=/etc/rpm/macros
  10. # for testing
  11. #RPMRC=/tmp/rpmrc
  12. #MACROS=/tmp/macros
  13.  
  14. [ -f $RPMRC ] || exit 0
  15.  
  16. [ -f $MACROS ] && {
  17.   echo "$MACROS already exists" 1>&2
  18.   exit 1
  19. }
  20.  
  21. DIRN="`dirname $MACROS`"
  22. [ -d "$DIRN" ] || mkdir -p "$DIRN"
  23. [ -d "$DIRN" ] || {
  24.   echo "could not create directory $DIRN" 1>&2
  25.   exit 1
  26. }
  27.  
  28. TMP=$(mktemp rpmrc.XXXXXX) || {
  29.   echo could not create temp file 1>&2
  30.   exit 1
  31. }
  32.  
  33. awk 'BEGIN {
  34.   macros="'"$MACROS"'"
  35.   # direct translation except underscore prepended
  36.   xlate["builddir"] = "_builddir"
  37.   xlate["buildshell"] = "_buildshell"
  38.   xlate["bzip2bin"] = "_bzip2bin"
  39.   xlate["dbpath"] = "_dbpath"
  40.   xlate["defaultdocdir"] = "_defaultdocdir"
  41.   xlate["excludedocs"] = "_excludedocs"
  42.   xlate["ftpport"] = "_ftpport"
  43.   xlate["ftpproxy"] = "_ftpproxy"
  44.   xlate["gzipbin"] = "_gzipbin"
  45.   xlate["instchangelog"] = "_instchangelog"
  46.   xlate["langpatt"] = "_langpatt"
  47.   xlate["netsharedpath"] = "_netsharedpath"
  48.   xlate["pgp_name"] = "_pgp_name"
  49.   xlate["pgp_path"] = "_pgp_path"
  50.   xlate["rpmdir"] = "_rpmdir"
  51.   xlate["rpmfilename"] = "_rpmfilename"
  52.   xlate["signature"] = "_signature"
  53.   xlate["sourcedir"] = "_sourcedir"
  54.   xlate["specdir"] = "_specdir"
  55.   xlate["srcrpmdir"] = "_srcrpmdir"
  56.   xlate["timecheck"] = "_timecheck"
  57.   xlate["tmppath"] = "_tmppath"
  58.   xlate["topdir"] = "_topdir"
  59.  
  60.   # direct translation with no underscore at all
  61.   xlate["buildroot"] = "buildroot"
  62.   xlate["distribution"] = "distribution"
  63.   xlate["packager"] = "packager"
  64.   xlate["vendor"] = "vendor"
  65.  
  66.   # simply remove
  67.   xlate["messagelevel"] = ""
  68.   xlate["require_distribution"] = ""
  69.   xlate["require_icon"] = ""
  70.   xlate["require_vendor"] = ""
  71. }
  72.  
  73. {
  74.   for (str in xlate) {
  75.     ms = "^" str ":"
  76.     if (match($1, ms)) {
  77.       if (xlate[str]) {
  78.         sub(ms, "%" xlate[str] " ")
  79.         print >> macros
  80.       }
  81.       # else get ignore and thus get rid of obsolete items
  82.       next
  83.     }
  84.     if (match ($1, "^fixperms:")) {
  85.       sub("^fixperms:", "%_fixperms chmod -R ")
  86.       print >> macros
  87.       next
  88.     }
  89.   }
  90.   print
  91.   next
  92. }
  93. ' < $RPMRC > $TMP || {
  94.   echo "could not convert $RPMRC entries to $MACROS entries" 1>&2
  95.   exit 1
  96. }
  97. if [ -s $TMP ] ; then
  98.   # don't mess with timestamp unless we have actually changed something
  99.   cat $TMP > $RPMRC && rm -f $TMP
  100.   [ -f $TMP ] && { echo "could not overwrite $RPMRC" 1>&2 ; exit 1 ; }
  101. fi
  102. rm -f $TMP
  103.  
  104. exit 0
  105.